package com.ll.blog.controller;

import com.ll.blog.repository.ArticleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;


@Controller
public class ArticleController {

    @Autowired
    private ArticleRepository articleRepository;

    // http://localhost:8080/my_blog?page=1&page_size=2
    @RequestMapping(value = "/my_blog", method = RequestMethod.GET)
    public String getCanUploadTeams(Model model, @RequestParam("page") Integer page, @RequestParam("page_size") Integer pageSize) {
        model.addAttribute("articles", articleRepository.findAllByPage(page, pageSize));
        Double total = articleRepository.count() + 0.0;
        model.addAttribute("totalPage", new Double(Math.ceil(total / pageSize)).intValue());
        model.addAttribute("page", page);
        model.addAttribute("pageSize", pageSize);
        return "index";
    }

}
